//
//  YCPassOtherView.swift
//  weiBoSwift
//
//  Created by 刘胤辰 on 16/7/24.
//  Copyright © 2016年 it.com. All rights reserved.
//

import UIKit
import SnapKit

class YCPassOtherView: UIView {

    //数据源
    var status : YCHomeStatus?{
        didSet{
            
            contenLabel.text=status?.retweeted_status?.text
            //判断有几张图片
            //卸载约束
            self.imageConstraint?.uninstall()
            if status?.retweeted_status?.pic_urls?.count > 0 {
                //赋值
                imagePassColView.imageLists=status?.retweeted_status?.pic_urls
                //设置约束
                self.snp_makeConstraints(closure: { (make) -> Void in
                    
                    self.imageConstraint=make.bottom.equalTo(imagePassColView.snp_bottom).offset(marginW).constraint
                })
                //显示配图
                imagePassColView.hidden=false
            }else{
                //设置约束
                self.snp_makeConstraints(closure: { (make) -> Void in
                    
                    self.imageConstraint=make.bottom.equalTo(contenLabel.snp_bottom).offset(marginW).constraint
                })
                
                imagePassColView.hidden=true
            }
        }
    }
    
    // MARK: -- 懒加载
    lazy var contenLabel:UILabel={
        
        let lab=UILabel(text: "", textColor: UIColor.blackColor(), font: 15)
        
        lab.preferredMaxLayoutWidth=SCREENW-20
        lab.numberOfLines=0
        
        return lab
    }()
    //设置配图
    private lazy var imagePassColView:YCHomeImageColView=YCHomeImageColView()
    //设置属性记录配图的约束
    private var imageConstraint:Constraint?
    
    override init(frame: CGRect) {
        
        super.init(frame: CGRectMake(0, 0, SCREENW, 50))
        
        self.backgroundColor=UIColor.whiteColor()
        
        //添加
        addSubview(contenLabel)
        addSubview(imagePassColView)
        //设置约束
        contenLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.leading.equalTo(self).offset(marginW)
        }
        imagePassColView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contenLabel.snp_bottom)
            make.leading.equalTo(self).offset(30)
        }
        self.snp_makeConstraints { (make) -> Void in
            
            self.imageConstraint=make.bottom.equalTo(imagePassColView.snp_bottom).offset(marginW).constraint
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
